package io.wdb.modules.generator.generator.controller.api;

import io.wdb.common.exception.RRException;
import io.wdb.modules.generator.generator.entity.web.BaseResponse;

public class BaseController {

	public String secret;
	/**
	 * 默认返回一个成功的对象
	 * @return
	 */
	protected BaseResponse success() {
		BaseResponse baseResponse = new BaseResponse();
		baseResponse.setResult(1);
		baseResponse.setCode(0);
		baseResponse.setMessage("操作成功");
		return baseResponse;
	}
	/**
	 * 操作异常
	 * @param e
	 * @return
	 */
	protected BaseResponse failed(Exception e) {
		BaseResponse baseResponse = new BaseResponse();
		baseResponse.setResult(0);
		if(e instanceof RRException) {
			RRException bizRuntimeException = (RRException) e;
			if(bizRuntimeException.getCode() == 0) {
				baseResponse.setResult(1);
			}
			baseResponse.setCode(bizRuntimeException.getCode());
			baseResponse.setMessage(bizRuntimeException.getMsg());
		}else {
			baseResponse.setCode(1010080099);
			baseResponse.setMessage("系统异常，请联系管理员");
		}
		return baseResponse;
	}
}
